export default {
  name: 'Goods',
  data () {
    return {
      goodsInfo: [],
      info: {
        query: '',
        pagenum: 1,
        pagesize: 8
      },
      total: 0,
      addGoodsInfo: {}
    }
  },
  created () {
    this.getGoodsList()
  },
  watch: {
    info: {
      handler () {
        this.getGoodsList()
      },
      deep: true
    }
  },
  methods: {
    async getGoodsList () {
      const { data } = await this.$get('goods', { params: this.info })
      this.goodsInfo = data.goods
      this.total = data.total
    },
    sizeChangeHandler (val) {
      this.info.pagesize = val
      this.getGoodsList()
    },
    currentChangeHandler (val) {
      this.info.pagenum = val
      this.getGoodsList()
    },
    async deleteHandler (val) {
      const { meta } = await this.$http.delete(`goods/${val}`)
      if (meta.status === 200) {
        this.$message({
          type: 'success',
          message: '已删除商品信息'
        })
        this.getGoodsList()
      }
    },
    editGoodsHandler (Info) {
      this.$router.push({
        path: `/addGoods/${Info.goods_id}`
      })
    },
    addGoods () {
      this.$router.push({
        path: '/addGoods/0'
      })
    }
  },
  filters: {
    format (val) {
      if (val === '0') {
        return '未通过'
      } else if (val === '1') {
        return '审核中'
      } else return '已审核'
    }
  }
}
